import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @Projectname: java8
 * @Filename: StreamTest
 * @Author: WangYang
 * @Data:2025/3/24
 * @Description: TODO
 */
public class StreamTest1 {

    public static void main(String[] args) {
        List<User> list = new ArrayList<>();
        list.add(new User("1","1",1));
        list.add(new User("2","2",2));
        list.add(new User("3","3",3));
        list.add(new User("4","4",4));
        list.add(new User("5","5",5));
        list.add(new User("6","6",6));
        list.add(new User("7","7",7));
        list.add(new User("7","7",7));
        boolean b = list.stream().allMatch(e -> e.getId() == "1");
        System.out.println(b);
        boolean b1 = list.stream().anyMatch(e -> e.getId() == "1");
        System.out.println(b1);
        boolean b2 = list.stream().noneMatch(e -> e.getId() == "1");
        System.out.println(b2);
        Optional<User> b3 = list.stream().findFirst();
        System.out.println(b3);
        Optional<User> b4 = list.stream().findAny();
        System.out.println(b4);
        long b5 = list.stream().count();
        System.out.println(b5);
        Optional<User> b6 = list.stream().max((o1, o2) -> Integer.compare(o1.getAge(), o2.getAge()));
        System.out.println(b6);
        Optional<User> b7 = list.stream().min((o1, o2) -> Integer.compare(o1.getAge(), o2.getAge()));
        System.out.println(b7);
        List<Integer> list1 = Arrays.asList(1, 4, 45, 3, 57, 23);
        Optional<Integer> b8 = list1.stream().max(Integer::compareTo);
        System.out.println(b8);

        List<Integer> list2 = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        Integer reduce = list2.stream().reduce(0, Integer::sum);
        System.out.println(reduce);

        List<User> collect = list.stream().filter(o -> o.getAge() > 3).collect(Collectors.toList());
        collect.forEach(System.out::println);
    }

}
